package JDBC;

import java.sql.*;

public class JDBCUtils {
    static public Connection getConnection() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/cgb2018";
        Connection c = DriverManager.getConnection(url,"root","root");
        return c;
    }

    static public void closeAll(Connection c, PreparedStatement s, ResultSet r) {
        if(c != null) {
            try{
                c.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if(s != null) {
            try{
                s.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if(r != null) {
            try{
                r.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    static public void closeAll(Connection c, Statement s) {
        if(c != null) {
            try{
                c.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if(s != null) {
            try{
                s.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

}
